package com.dididoctor.doctor.Activity.PatientDetial;

import android.view.KeyEvent;
import android.view.View;
import android.widget.AbsListView;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Ui.customlistview.OnRefreshListener;
import com.dididoctor.doctor.Ui.customlistview.RefreshListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by boy on 2016/4/21.
 */
public class CaseHistoryActivity extends EduActivity implements CaseHistoryView{
    private RefreshListView mlvCaseHistory;
    private CaseHistoryAdapter adapter;
    private CaseHistoryPresenter presenter;
    private int pageIndex=1;
    private List<CaseHistoryBean> messageData = new ArrayList<CaseHistoryBean>();
    private String  clientId,status,isSign;
    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_casehistory);
        clientId = getIntent().getStringExtra("clientId");

        status = getIntent().getStringExtra("status");

        isSign =getIntent().getStringExtra("isSign");
    }

    @Override
    public void init() {

        /** 界面**/
        initview();
    }

    private void initview() {

        mlvCaseHistory = (RefreshListView) findViewById(R.id.lv_casehostory);
        mlvCaseHistory.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onPullDownRefresh() {
                pageIndex = 1;
                presenter.lunch(pageIndex, clientId);
            }

            @Override
            public void onLoadMoring() {
                pageIndex++;
                presenter.lunch(pageIndex, clientId);
            }

            @Override
            public void onScrollListener(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
        mlvCaseHistory.setHeadAndFoot(true, true);
        adapter = new CaseHistoryAdapter(CaseHistoryActivity.this, messageData);
        mlvCaseHistory.setAdapter(adapter);
        presenter = new CaseHistoryPresenter(CaseHistoryActivity.this, this);
        presenter.lunch(pageIndex, clientId);
    }

    @Override
    public void onClickEvent(View view) {

    }


    @Override
    public void getdoctorfail() {
        showToastMessage("网络连接失败，请检查您的网络设置");
        mlvCaseHistory.onRefreshFinish();
    }

    @Override
    public void getdoctorsucced(List<CaseHistoryBean> CaseHistorys) {
        if (CaseHistorys != null && CaseHistorys.size() > 0) {
            if (pageIndex == 1) {
                this.messageData.clear();
                adapter.setData(CaseHistorys);
                mlvCaseHistory.onRefreshFinish();
            }else{
                if (CaseHistorys.size() < ConstantValue.LOAD_MESSAGE_COUNT) {
                    adapter.addData(CaseHistorys);
                    mlvCaseHistory.showNoMoreData();
                } else {
                    adapter.addData(CaseHistorys);
                    mlvCaseHistory.hideNoMoreData();
                }
            }
            adapter.notifyDataSetChanged();
        } else {
            if (pageIndex == 1) {
                mlvCaseHistory.onRefreshFinish();
            }else{
                mlvCaseHistory.showNoMoreData();
                adapter.notifyDataSetChanged();
            }
        }
    }
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        return false;
    }
}
